# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libdsm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.4.3
pkgrel=3
pkgdesc="SMB protocol client implementation in pure old C, with a lot less features than Samba but with a much simpler, and a more permissive license (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url="https://videolabs.github.io/libdsm"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-libtasn1"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread-git")
options=('strip' 'staticlibs')
source=(https://github.com/videolabs/libdsm/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.xz
        001-fix-build-on-clang-15.patch)
sha256sums=('d31921bd6f6a23878266b945731f7d57505472ef85d66f944c43b9f8eacc2a8a'
            'a354a075f0cc2e3e3753e5e1845d4b12574381060d8774d4442742dc44fc7f1a')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ../001-fix-build-on-clang-15.patch
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  LDFLAGS+=" -lws2_32"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --default-library=both \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

package() {
  cd build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
